import { createRouter, createWebHashHistory } from "vue-router";
import HomeView from "@/views/HomePage.vue";
import TestView from "@/views/TestView.vue";
import LoginView from "@/views/LoginView.vue";
import IssueHall from "@/views/IssueHall.vue";
import UploadManuscript from "@/views/UploadManuscript.vue";
import ThreeView from "@/views/ThreeView.vue";
import UpdateMessage from "@/views/UpdateMessage.vue";
const routes = [
  {
    path: "/",
    name: "home",
    component: HomeView,
    meta: {
      layout: "MainLayout",
      title: "芸窗-您的期刊采编平台",
    },
  },
  {
    path: "/test",
    name: "test",
    component: TestView,
    meta: {
      title: "测试页面",
      layout: "MainLayout",
    },
  },
  {
    path: "/issuehall",
    name: "issuehall",
    component: IssueHall,
    meta: {
      title: "期刊大厅",
      layout: "MainLayout",
    },
  },
  {
    path: "/uploadManuscript",
    name: "uploadManuscript",
    component: UploadManuscript,
    meta: {
      title: "上传稿件",
      layout: "MainLayout",
    },
  },
  {
    path: "/three",
    name: "three",
    component: ThreeView,
    meta: {
      title: "芸窗3D",
    },
  },
  {
    path: "/login",
    name: "login",
    component: LoginView,
    meta: {
      title: "加入芸窗",
    },
  },
  {
    path: "/updateMessage",
    name: "updateMessage",
    component: UpdateMessage,
    meta: {
      title: "修改信息",
      layout: "MainLayout",
    },
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});
// 全局前置守卫
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  if (to.meta.favicon) {
    document.head.innerHTML = `<link rel="icon" href="${to.meta.favicon}">`;
  }
  next();
});

export default router;
